﻿using System;

namespace Innovative.ProXr
{
	/// <summary>
	/// 
	/// </summary>
	public class TimeSpanResponseConverter : IResponseConverter<TimeSpan>
	{
		TimeSpan IResponseConverter<TimeSpan>.Convert(RelayByte[] response)
		{
			TimeSpan returnValue = TimeSpan.Zero;

			if (response.Length == 3)
			{
				returnValue = TimeSpan.FromHours(response[0]).Add(TimeSpan.FromMinutes(response[1]).Add(TimeSpan.FromSeconds(response[2])));
			}
			else
			{
				throw new InvalidResponseException("The TimeSpanResponseConverter converter expects 3 bytes in the response.");
			}

			return returnValue;
		}
	}
}
